package com.wu.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.wu.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Scope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @ClassName WeiXinArticleController
 * @Author wuxuan
 * @Date 2019/2/17 21:29
 * @Version 1.0
 * @Description
 **/
@RestController
@Scope("prototype")
public class WeiXinArticleController {

    @Autowired
    @Qualifier(value = "articleService")
    ArticleService service;

    @Value("${ArticlePageSize}")
    int articlePageSize;

    ObjectMapper mapper = new ObjectMapper();

    /**
     * @MethodName getArticleList
     * @Data 2019/2/18 12:12
     * @Author wuxuan
     * @Description 过去微信精选文章给各应用端
     **/
    @GetMapping("/ArticleList")
    public String getArticleList(@RequestParam int currentPage) throws JsonProcessingException {
        List<Map> article = service.getArticle(currentPage, articlePageSize);
        return  mapper.writeValueAsString(article);
    }

}
